package com.adastros.buildingmanager;

import com.adastros.buildingmanager.model.Address;
import com.adastros.buildingmanager.model.Contact;
import com.adastros.buildingmanager.model.Person;
import com.adastros.buildingmanager.model.water.DataModel;
import java.io.IOException;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Transaction;
//import org.apache.pivot.collections.Map;
//import org.apache.pivot.wtk.Application;
//import org.apache.pivot.wtk.Display;

/**
 * Hello world!
 *
 */
public class App /*implements Application */{

  public static void main(String[] args) {
    
    try {
      
      //DataModel dataModel = new DataModel("C:\\Documents and Settings\\developer\\Mis documentos\\Pocket_PC My Documents\\water.meters.data") ;
    
      //dataModel.exportToXLS("C:\\Documents and Settings\\developer\\Mis documentos\\Pocket_PC My Documents\\medidores.xls");
      
      
      PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("BuildingManager");
      PersistenceManager pm = pmf.getPersistenceManager();
      Transaction tx = pm.currentTransaction();
      
      try {
        tx.begin();
        
        Person person = pm.getObjectById(Person.class, UUID.fromString("659372a0-805a-45d1-bf3c-8afcaee656fa")) ;
        
        System.out.println(person.toString()) ;
        
        //Person person = new Person();
//      Address address = new Address("Contralmirante Villar", "774", "302", "Lima 18", "Miraflores", "Lima", "Perú") ;
//      Contact contact = new Contact(address, "2220852", "990015737", "correo@correo.net");
        
        Contact contact = person.getContact() ;
        
        contact.setEmailAddress("correo@correo.2.nuevo.net");
        
//      person.setContact(contact);
//      person.setName("Rubén");
//      person.setSurName("Carbonell Sánchez");
//      person.setSex(Person.Sex.MALE);
//      person.setKind(Person.Kind.ADULT);
        
        //pm.makePersistent(person);
        tx.commit();
      } finally {
        if (tx.isActive()) {
          tx.rollback();
        }
        pm.close();
      }
    } catch (Exception ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
  }

//  public void startup(Display display, Map<String, String> properties) throws Exception {
//    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
//  }
//
//  public boolean shutdown(boolean optional) throws Exception {
//    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
//  }
//
//  public void suspend() throws Exception {
//    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
//  }
//
//  public void resume() throws Exception {
//    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
//  }
}
